package com.wly.ui
{
	import com.wly.data.ItemVO;
	import com.wly.data.ResourceCache;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	public class ItemDetailInfo extends Sprite
	{
		private var _tfName:TextField;
		private var _tfWidth:TextField;
		private var _tfHeight:TextField;
		private var _tfTypes:TextField;
		private var _mcImg:Sprite;
		private var _bmp:Bitmap;
		private var _item:ItemVO;
		
		public function ItemDetailInfo()
		{
			super();
			initChilds();
		}
		
		private function initChilds():void
		{
			_tfName   = getChildByName("tfName") as TextField;
			_tfWidth  = getChildByName("tfWidth") as TextField;
			_tfHeight = getChildByName("tfHeight") as TextField;
			_tfTypes  = getChildByName("tfTypes") as TextField;
			_mcImg    = getChildByName("mcImg") as Sprite;
		}
		
		public function getItem():ItemVO
		{
			return _item;
		}
		
		public function setItemInfo(item:ItemVO):void
		{

			if(!item)
			{
				return;
			}
			
			_item =  item;
			_tfName.text  = _item.url;
			_tfWidth.text = _item.width.toString();
			_tfHeight.text= _item.height.toString();
			_tfTypes.text = _item.types.toString();
			
			if(_bmp)
			{
				_mcImg.removeChild(_bmp);
				_bmp = null;
			}
			_bmp = new Bitmap;
			_bmp.bitmapData = ResourceCache.getInstance().getResourseByUrl(_item.url) as BitmapData;
			if(_bmp)
			{
				_mcImg.addChild(_bmp);
				_bmp.x = -item.width/2;
				_bmp.y = -item.height/2;
			}
		}
	}
}